package spe.model.notation;


import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import spe.model.spem.NodeElement;
import spe.model.spem.NodeElementImpl;

/**
 *	This class acts as element container before they are drawn on an editor  
 */

public class SPEMDiagramImpl extends NodeElementImpl implements SPEMDiagram
{
	private HashMap<Integer, NodeElement> elements = new HashMap<Integer, NodeElement>();
	private List<Link> links = new ArrayList<Link>();
	
	public SPEMDiagramImpl()
	{
	}
	
	@Override
	public List<NodeElement> getElements() 
	{
		Collection<NodeElement> coll = elements.values();
		//return new ArrayList<NodeElement>(coll);
		return new ArrayList<NodeElement>( coll );
	}

	@Override
	public void setElements(List<NodeElement> elements) 
	{
		Object oldValue = this.elements.clone();
		for(NodeElement e: elements)
		{
			this.elements.put(e.hashCode(), e);
		}
		firePropertyChange("elements", oldValue, elements);
	}

	@Override
	public void addElement(NodeElement element) 
	{
		//Object oldValue = this.elements.clone();
		//System.out.println(String.format("[SPEMDiagramImpl] New Element: %s", element));
		Object oldValue = null;
		elements.put(element.hashCode(), element);
		firePropertyChange("ChildElement", oldValue, element);
	}

	@Override
	public void removeElement(NodeElement element) 
	{
		elements.remove(element.hashCode());
		
		firePropertyChange("Elements", element, null);
	}

	@Override
	public NodeElement getNodeElementById(String name) 
	{
		return elements.get(name);
	}

	@Override
	public void addLink(Link l) 
	{
		links.add(l);
	}

	@Override
	public void removeLink(Link l) 
	{
		links.remove(l);
	}
	
}
